package org.asg.dis.service;

import org.asg.dis.model.Role;
import org.asg.dis.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class RbacService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private RoleRepository roleRepository;

    public List<Role> findAll(){
        return roleRepository.findAll();
    }

    public void cacheRolesAndPermissions(Map<String, Set<String>> rolesPermissions) {
        redisTemplate.opsForValue().set("rolesPermissions", rolesPermissions);
    }

    public Map<String, Set<String>> getRolesAndPermissions() {
        return (Map<String, Set<String>>) redisTemplate.opsForValue().get("rolesPermissions");
    }
}
